package com.jnu.experience07;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class DemoMainActivity extends AppCompatActivity {
    private TextView mTextView;
    private Button mButton;
    private NumModel mNumModel;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_main);

        mTextView = findViewById(R.id.tv_show);
        mButton = findViewById(R.id.btn_add);
        mNumModel = new NumModel();

        mButton.setOnClickListener(new View.OnClickListener() {//接收来自View的事件
            public void onClick(View v) {
                mNumModel.add(DemoMainActivity.this);//通知Model处理数据
            }
        });
    }

    public void updateUI(String text) {//更新UI
        mTextView.setText(text);
    }

    class NumModel {
        private int num = 0;

        public void add(DemoMainActivity activity) {
            num = ++num;//更新数据
            activity.updateUI(num + "");//更新UI
        }

    }
}